<template>
    <div class="admin-wrap">
        <!--用户信息-->
        <router-link to="/admin/user-info" class="user-info" v-if="user">
            <l-image class="user-avatar"
                     :src="user.avatar" width="95" height="95"></l-image>
            <div class="name">
                {{user.userName}}
            </div>
            <router-link class="tixian flex al-c jc-fe" to="/admin/wallet" v-if="postIds.includes(6)">立即提现</router-link>
        </router-link>
        <div class="no-login flex al-c jc-c text-center" v-else>
            <div>
                <div>立即登陆</div>
                <l-button class="btn-g" to="/login">登陆/注册</l-button>
            </div>
        </div>
        <div class="w">
            <div class="m-card">
                <div class="h flex jc-sb al-c">
                    <div>我的订单</div>
                    <router-link class="more" to="/admin/order">查看全部
                        <i class="iconfont icon-arrow-right"></i></router-link>
                </div>
                <div class="b order-type">
                    <router-link to="/admin/order" class="item">
                        <div class="icon 1"><img src="../../assets/img/icon/o-1.png" alt=""></div>
                        <div>全部订单</div>
                    </router-link>
                    <router-link tag="div" class="item" to="/admin/order?type=0">
                        <div class="icon 2"><img src="../../assets/img/icon/o-2.png" alt=""></div>
                        <div>未支付</div>
                    </router-link>
                    <router-link tag="div" class="item" to="/admin/order?type=1">
                        <div class="icon i-3"><img src="../../assets/img/icon/o-3.png" alt=""></div>
                        <div>支付成功</div>
                    </router-link>
                    <div class="item">
                        <div class="icon i-4"><img src="../../assets/img/icon/o-4.png" alt=""></div>
                        <div>已删除</div>
                    </div>
                </div>
            </div>
            <div class="link-list">
                <router-link to="/admin/user" class="item">
                    <div class="icon"><i class="iconfont icon-admin2" style="color: #6fa4fb;"></i></div>
                    <div>账号管理</div>
                </router-link>
                <router-link to="/consult" class="item">
                    <div class="icon"><i class="iconfont icon-consultation" style="color: #9bab3f;"></i></div>
                    <div>我要咨询</div>
                </router-link>
                <router-link to="/help" class="item">
                    <div class="icon"><i class="iconfont iconhelp" style="color: #f18657;"></i></div>
                    <div>常见问题</div>
                </router-link>
                <div class="item" @click="handlerOutLogin" v-if="!isWx">
                    <div class="icon"><i class="iconfont icon-set" style="color: #ed534c;"></i></div>
                    <div>退出登陆</div>
                </div>
            </div>
        </div>

    </div>
</template>

<script>
    import WxSdk from '@/pages/mobile/lib/wx-sdk'

    export default {
        name: "AdminIndex",
        data() {
            return {
                wx: null,
                balanceInfo: null
            }
        },
        computed: {
            user() {
                return this.$root.userInfo || null
            },
            postIds() {
                if (this.$root.userInfo) {
                    return this.$root.userInfo.postIds
                }
                return []
            },
            isWx(){
                return this.$utils.browser.isWx
            }
        },
        components: {},
        created() {
            this.wx = new WxSdk()
            this.$root.getUserInfo()
            if (this.$utils.store.get('userInfo') && this.$utils.store.get('userInfo').postIds.includes(6)) {
                this.$api.user.balance().then(res => {
                    res.data.balances = res.data.balances || 0
                    res.data.witAmount = res.data.witAmount || 0
                    res.data.allAmount = res.data.allAmount || 0
                    this.balanceInfo = res.data
                })
            }
        },
        methods: {
            handlerScan() {
                window.$wx.scanQRCode({
                    needResult: 1,
                    scanType: ['qrCode'],
                    success: res => {
                        if (res.resultStr.includes('www.huankeyanxue.com/mobile.html#/admin/sign?id=')) {
                            this.$router.push(`/admin/sign?id=${res.resultStr.split('id=')[1]}`)
                        } else {
                            this.$notify({
                                type: 'warning',
                                message: '请扫描正确的二维码'
                            })
                        }
                    }
                })
            },
            handlerOutLogin() {
                this.$utils.store.remove('token')
                this.$utils.store.remove('userInfo')
                this.$router.push('login')
                setTimeout(() => {
                    window.location.reload()
                })
            }
        },
    }
</script>

<style lang="scss">
    @import "./style";
</style>
